package net.zdreamer.geracomium.adapter;

import java.util.ArrayList;
import java.util.List;

import net.zdreamer.geracomium.ui.GeracomiumIntroFragment;
import net.zdreamer.geracomium.ui.HomeFragment;
import net.zdreamer.geracomium.ui.home.GeracomiumDetailsActivity;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.example.geracomium.R;

public class GeracomiumIntroViewPagerAdapter extends PagerAdapter{
	// 界面列表
		List<String> ImageURL; /* 要加载的图片地址 */
		private List<View> views;
		private Activity activity;
		private static final String SHAREDPREFERENCES_NAME = "first_pref";

		public GeracomiumIntroViewPagerAdapter(Fragment fragment) {
			this.activity = fragment.getActivity();

			/*
			 * test code
			 */
			views = new ArrayList<View>();
			ImageView img1 = new ImageView(fragment.getActivity());
			img1.setBackgroundResource(R.drawable.intro);
			views.add(img1);

			ImageView img2 = new ImageView(fragment.getActivity());
			img2.setBackgroundResource(R.drawable.intro);
			views.add(img2);

			ImageView img3 = new ImageView(fragment.getActivity());
			img3.setBackgroundResource(R.drawable.intro);
			views.add(img3);

			ImageView img4 = new ImageView(fragment.getActivity());
			img4.setBackgroundResource(R.drawable.intro);
			views.add(img4);
			
			ImageView img5 = new ImageView(fragment.getActivity());
			img4.setBackgroundResource(R.drawable.intro);
			views.add(img5);

		}
		
		   public void bindData(List<String> list) {
		        this.ImageURL = list;
		        System.out.println("ooo" + list);
		    }


		
		@Override
	    public int getCount() {
	        // TODO Auto-generated method stub
	        return views.size();
	    }

	    @Override
	    public boolean isViewFromObject(View arg0, Object arg1) {
	        // TODO Auto-generated method stub
	        return arg0 == arg1;
	    }

	    @Override
	    public void destroyItem(ViewGroup container, int position, Object object) {
	        // TODO Auto-generated method stub
	        ((ViewPager) container).removeView(container);
	    }

	    @Override
	    public Object instantiateItem(ViewGroup container, final int position) {
	        // TODO Auto-generated method stub
//	        ImageView imageView = new ImageView(activity);
	    	ImageView imageView = new ImageView(activity);
	    	imageView.setImageResource(R.drawable.intro);
	        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
	        imageView.setPadding(0, 0, 0, 0);
//	        ImageLoader imageLoader = new ImageLoader(queue, imageCache);
//	        ImageListener imageListener =
//	                imageLoader.getImageListener(imageView, R.drawable.loading53, R.drawable.loading53);
//	        imageLoader.get(mListviews.get(position), imageListener);

//	        imageView.setOnClickListener(new OnClickListener() {
//	            @Override
//	            public void onClick(View arg0) {
//	                // Toast.makeText(context, "广告位跳转", Toast.LENGTH_SHORT).show();
//	                if (null != mOnItemClickListener) {
//	                    mOnItemClickListener.onItemClickListener(position);
//	                }
//
//	            }
//	        });

	        container.addView(imageView);
	        return imageView;
	    }

	    private OnItemClickListener mOnItemClickListener;

	    public void setOnItemOnClickListener(OnItemClickListener listener) {
	        mOnItemClickListener = listener;
	    }

	    public interface OnItemClickListener {
	        public void onItemClickListener(int position);
	    }

}
